require("SOD/tools/OpenStudio/Collection")
require("SOD/model/drawVolumeModel")
require("SOD/model/drawConstructionModel")
require("SOD/model/drawFootprint")

module SOD
  
  class DrawModelInterface
    
    attr_reader :drawVolumes, :drawConstruction, :drawFootprint
    attr_reader :reset
    attr_accessor :active_model
    
    def initialize
      @active_model = Collection.new
      @drawVolumeModel = DrawVolumeModel.new
      @drawConstructionModel = DrawConstructionModel.new
      @drawFootprintTool = DrawFootprint.new
    end
    
    def drawVolumes
      self.reset
      Sketchup.active_model.active_layer = Sketchup.active_model.layers[0]
      Sketchup.active_model.start_operation("drawModel")
        @drawVolumeModel.draw
        @active_model.each { |g| puts g } if $debug
      Sketchup.active_model.commit_operation
      #self.drawCores
    end
    
    def drawConstruction
      self.reset
      Sketchup.active_model.active_layer = Sketchup.active_model.layers[0]
      #Sketchup.active_model.active_layer = sketchLayer
      Sketchup.active_model.start_operation("drawModel")
        @drawConstructionModel.draw
        @active_model.each { |g| puts g } if $debug
      Sketchup.active_model.commit_operation
    end
    
    def drawFootprint
      self.reset
      Sketchup.active_model.start_operation("drawModel")
        @drawFootprintTool.draw
      Sketchup.active_model.commit_operation
    end
    
    def reset
      @active_model.each do |group|
	if group.valid?
	  puts group if $debug
	  Sketchup.active_model.active_entities.erase_entities group
	end
      end
      @active_model.clear
    end
    
  end

end
